import 'package:flutter/material.dart';
import '../model/post.dart';

class viewDemo extends StatelessWidget{
  Widget _gridItemBuilder(BuildContext context,int index){
return Container(
  child:Image.network(
    posts[index].imageUrl,
    fit: BoxFit.cover,
  )
);
  }
   @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return GridView.builder(
      itemCount: posts.length,
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
      crossAxisCount: 3,
      crossAxisSpacing: 5.0,
      mainAxisSpacing: 5.0
      ), 
      itemBuilder: _gridItemBuilder,
      );
  }
}

class GridViewDemo extends StatelessWidget{
  @override
  Widget build(BuildContext context) {

   List<Widget> _builderTiles(int length){
  return List.generate(length, (index) {
   return Container(
     color:Colors.grey[300],
     alignment: Alignment(0, 0),
    );
     });
  }
   return GridView.count(
      crossAxisCount: 3,
      crossAxisSpacing: 10.0,
      mainAxisSpacing: 10.0,
      children: _builderTiles(100),
      );
  }
}

class pageViewBuilder extends StatelessWidget{
Widget _pageItemBuilder(BuildContext context,int index){
return Stack(
children: <Widget>[
  SizedBox.expand(
child:Image.network(
  posts[index].imageUrl,
  fit: BoxFit.cover,
),
  ),
  Positioned(
    bottom: 8.0,
    left: 8.0,
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
     children: <Widget>[
        Text(
         posts[index].title,
         style: TextStyle(fontWeight:FontWeight.bold),
        ),
        Text(
         posts[index].author,
         style: TextStyle(fontWeight:FontWeight.normal),
       ),
     ],

  ))
],

);
}
@override
  Widget build(BuildContext context) {
    return PageView.builder(
      itemCount: posts.length,
      itemBuilder: _pageItemBuilder
    );
  }
}
class pageviewDemo extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return PageView(
     // scrollDirection: Axis.vertical,
     controller: PageController(
       initialPage: 1,
       viewportFraction: 1.0
     ),
     onPageChanged: (currentPage) => debugPrint('page:$currentPage'),
     children: <Widget>[
      Container(
        color: Colors.brown[900],
        alignment: Alignment.center,
        child: Text('ONE',style: TextStyle(fontSize:32,color:Colors.white)),
      ),
      Container(
        color: Colors.green[900],
        alignment: Alignment.center,
        child: Text('TWO',style: TextStyle(fontSize:32,color:Colors.white)),
      ),
      Container(
        color: Colors.grey[900],
        alignment: Alignment.center,
        child: Text('THREE',style: TextStyle(fontSize:32,color:Colors.white)),
      )
     ],

    );
  }
}